package com.cn.wangxin.controller.weather;

import com.cn.wangxin.annotation.AccessRequired;
import com.cn.wangxin.service.weather.WeatherService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 功能描述 TODO
 *
 * @Created Time 2016/9/23
 * @Edited Time 2016/9/23
 * @Created by wangxin43
 */
@Controller
@RequestMapping("/WeatherController")
public class WeatherController {
    private Logger logger = LoggerFactory.getLogger(WeatherController.class);

    @Resource
    private WeatherService weatherService;

    /**
     * 根据城市获取天气
     * http://apistore.baidu.com/apiworks/servicedetail/2573.html
     * @param httpServletRequest
     * @return
     */
    @RequestMapping(value="/weather" ,method = {RequestMethod.GET, RequestMethod.POST},
            produces={"application/json;charset=UTF-8"})
    public @ResponseBody String getWeatherByCity(HttpServletRequest httpServletRequest) {
        String city = httpServletRequest.getParameter("city");
        logger.info("WeatherController getWeatherByCity city is {}",city);
        String weather = weatherService.getWeather(city);
        return weather;
    }
}
